package com.jn.zhinongbao.adapter.bean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 聊天室实体类
 */
public class ChatRoom {
    private String id; // 聊天室ID (userId_merchantId)
    private int userId; // 用户ID
    private int merchantId; // 商家ID
    private String userName; // 用户名
    private String merchantName; // 商家名
    private String lastMessage; // 最后一条消息
    private String lastMessageTime; // 最后消息时间
    private int unreadCount; // 未读消息数量
    private String userAvatar; // 用户头像
    private String merchantAvatar; // 商家头像

    public ChatRoom() {
        this.lastMessageTime = getCurrentTimeString();
        this.unreadCount = 0;
    }

    public ChatRoom(int userId, int merchantId, String userName, String merchantName) {
        this.userId = userId;
        this.merchantId = merchantId;
        this.userName = userName;
        this.merchantName = merchantName;
        this.id = userId + "_" + merchantId;
        this.lastMessageTime = getCurrentTimeString();
        this.unreadCount = 0;
    }

    private String getCurrentTimeString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        return sdf.format(new Date());
    }

    // Getters and Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(int merchantId) {
        this.merchantId = merchantId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getMerchantName() {
        return merchantName;
    }

    public void setMerchantName(String merchantName) {
        this.merchantName = merchantName;
    }

    public String getLastMessage() {
        return lastMessage;
    }

    public void setLastMessage(String lastMessage) {
        this.lastMessage = lastMessage;
    }

    public String getLastMessageTime() {
        return lastMessageTime;
    }

    public void setLastMessageTime(String lastMessageTime) {
        this.lastMessageTime = lastMessageTime;
    }

    public int getUnreadCount() {
        return unreadCount;
    }

    public void setUnreadCount(int unreadCount) {
        this.unreadCount = unreadCount;
    }

    public String getUserAvatar() {
        return userAvatar;
    }

    public void setUserAvatar(String userAvatar) {
        this.userAvatar = userAvatar;
    }

    public String getMerchantAvatar() {
        return merchantAvatar;
    }

    public void setMerchantAvatar(String merchantAvatar) {
        this.merchantAvatar = merchantAvatar;
    }

    /**
     * 获取对方的名称（相对于当前用户）
     * @param currentUserId 当前用户ID
     * @return 对方的名称
     */
    public String getOtherUserName(int currentUserId) {
        if (currentUserId == userId) {
            return merchantName;
        } else {
            return userName;
        }
    }

    /**
     * 获取对方的ID（相对于当前用户）
     * @param currentUserId 当前用户ID
     * @return 对方的ID
     */
    public int getOtherUserId(int currentUserId) {
        if (currentUserId == userId) {
            return merchantId;
        } else {
            return userId;
        }
    }
} 